﻿//===============================================================================
//	LuaGlueCommon.h
//	LUA -> C++ 公共定义
//===============================================================================

#pragma once

#include <cstdint>

////-------------------------------------------------------------------------------
static const uint32_t size_256 = 256;
static const uint32_t size_64 = 64;
//-------------------------------------------------------------------------------
#define MacroCheckParamCount(ls, c, s) { \
	int32_t _count = lua_gettop((ls)); \
	if (_count < (c)) { \
		char _str[size_256] = {0}; \
		snprintf(_str, size_256 - 1, \
			"MacroCheckParamCount ERROR : function [%s] count [%d] vs [%d].\n", \
			(s), c, _count); \
		fprintf(stderr, _str); \
		return 0; } }

#define MacroIsNumber(ls, idx, s) { \
	if ( ! lua_isnumber((ls), (idx)) ) { \
		char _str[size_256] = {0}; \
		snprintf(_str, size_256 - 1, \
			"MacroIsNumber ERROR : function [%s] %u is not number.\n", \
			(s), (idx) ); \
		fprintf(stderr, _str); \
		return 0; } }

#define MacroIsString(ls, idx, s) { \
	if (!lua_isstring((ls), (idx))) { \
		char _str[size_256] = { 0 }; \
		snprintf(_str, size_256 - 1, \
			"MacroIsString ERROR : function [%s] %d is not string.\n", \
			(s), (idx) ); \
		fprintf(stderr, _str); \
		return 0; } }

//-------------------------------------------------------------------------------
#define MacroGetIntegerArgument(ls, idx) (luaL_optinteger((ls), (idx), 0));
#define MacroGetUnsignedIntegerArgument(ls, idx) (uint32_t)(luaL_optinteger((ls), (idx), 0));
#define MacroGetNumberArgument(ls, idx) luaL_optnumber((ls), (idx), 0.0);
#define MacroGetStringArgument(ls, idx) luaL_optstring((ls), (idx), nullptr);

//-------------------------------------------------------------------------------
#define MacroPushInteger(ls, val) lua_pushinteger((ls), (val));
#define MacroPushNumber(ls, val) lua_pushnumber((ls), (val));
#define MacroPushString(ls, val) lua_pushstring((ls), (val));

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------